package com.kaifamiao.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class ListTest2 {

	public static void main(String[] args) {
		List<String> list = new ArrayList<>();
		list.add( "唐三藏" );
		list.add( "孙悟空" );
		list.add( "白龙马" );
		list.add( "猪八戒" );
		list.add( "沙悟净" );
		
		Iterator<String> it = list.iterator(); 
		while( it.hasNext() ) {
			String name = it.next();
			System.out.println( name );
		}
		
		System.out.println( "- - - ".repeat( 5 ) );
		
		ListIterator<String> listItor = list.listIterator(); // List#listIterator()
		
		while( listItor.hasNext() ) {
			String name = listItor.next();
			System.out.println( name );
		}
		
		System.out.println( "- - - ".repeat( 5 ) );
		
		while( listItor.hasPrevious() ) {
			String name = listItor.previous();
			System.out.println( name );
		}
		
		System.out.println( "- - - ".repeat( 5 ) );
		
		listItor = list.listIterator( 2 ); // List#listIterator(int)
		
		while( listItor.hasNext() ) {
			String name = listItor.next();
			System.out.println( name );
		}
		
		System.out.println( "- - - ".repeat( 5 ) );
		
		while( listItor.hasPrevious() ) {
			String name = listItor.previous();
			System.out.println( name );
		}
		
	}

}
